<?php
class shopOrder extends logCAr
{
    public $startDay; //开始日期
    public $endDay; //结束日期



	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
	
	/* reset db */
	public function getDbConnection()
	{
		self::$db=Yii::app()->db1;
		if(self::$db instanceof CDbConnection) return self::$db;
	}

    public function relations()
    {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
            'user' => array(self::BELONGS_TO, 'shopUser', 'user_id'),
        );
    }
	
    public function tableName()
	{
		return '{{shop_order}}';
	}
    /* rules */
    public function rules()
    {
        return array(
            array('goods_info,status,order_no,startDay,endDay', 'safe', 'on'=>'search'),
        );
    }

    public function search()
    {
        $criteria=new CDbCriteria;
        if ($this->startDay && $this->endDay && $this->endDay >= $this->startDay) {
            $criteria->addBetweenCondition('create_time' , date("Y-m-d",strtotime($this->startDay)) . ' 00:00:00',date("Y-m-d",strtotime($this->endDay)) . ' 23:59:59');
        }
        $criteria->order='create_time desc';
        $criteria->compare('del_flag',0);
        $criteria->compare('status',$this->status);
        $criteria->compare('order_no',$this->order_no);
        if ($this->goods_info)$criteria->compare('goods_info',$this->goods_info,true);
        return new CActiveDataProvider($this, array(
            'criteria'=>$criteria,
        ));
    }

    public function attributeLabels() //表单字段label,如不定义，默认使用字段名称做为label
    {
        return array(
            'startDay' => '开始日期',
            'endDay' => '结束日期',
        );
    }

    static public function statusArr()
    {
        return array(
            '0' => '已支付',
            '1' => '已发货',
            '2' => '已完成',
        );
    }
}